package com.qianfeng.yime.util;

import android.app.Activity;
import android.app.Application;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by Fcy on 2015/3/11.
 */

/**
 * 用于在任何位置退出应用的管理器，单例
 */
public class ExitApplication extends Application {
    private static ExitApplication instance;
    private List<Activity> list = new LinkedList<Activity>();

    private ExitApplication() {
    }

    public ExitApplication getInstance() {
        if (instance == null) {
            instance = new ExitApplication();
        }
        return instance;
    }

    /**
     * @param activity
     */
    public void addActivity(Activity activity) {
        list.add(activity);
    }

    /**
     * 退出应用
     */
    public void exit() {
        for (Activity activity : list) {
            activity.finish();
        }
        System.exit(0);
    }
}
